﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace nToDo
{
    public partial class Settings : Form
    {
        string appName = string.Empty;
        public Settings()
        {
            InitializeComponent();
            this.appName = Properties.Resources.ApplicationName;
        }

        private void storeFolder_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show(string.Format("Store Folder will help you to change the location of the nToDo database.{0}The nTodo.sdf database file should exists in the selected location,{0}otherwise application may crash.{0}Would you like to continue?", Environment.NewLine), this.appName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                using (FolderBrowserDialog dlg = new FolderBrowserDialog())
                {
                    dlg.ShowNewFolderButton = false;
                    dlg.SelectedPath = Properties.Settings.Default.DbPath;
                    dlg.Description = "Select the new Folder location";
                    if (dlg.ShowDialog(this) == DialogResult.OK)
                    {
                        Properties.Settings.Default.DbPath = dlg.SelectedPath;
                        Properties.Settings.Default.Save();
                        MessageBox.Show("Store Folder updated successfully.", this.appName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
        }

        private void compactButton_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show(string.Format("Compact Database option will help you to compact the size of the nToDo database.{0}Would you like to continue?", Environment.NewLine), this.appName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                DataAccess.GetInstance().CloseConnection();
                DataManagement.Compact();
                MessageBox.Show("Compact database completed successfully.", this.appName, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
    }
}
